package p2d

import (
	"encoding/binary"
	"hy_808/protocol/jtt808"
)

// 终端注册应答 0x8100
type PlatformRegAnswer struct {
	jtt808.Jtt808
	AnswerRegSN uint16 //应答流水号 对应的终端注册消息的流水号
	Result      byte   //结果 0：成功；1：车辆已被注册；2：数据库中无该车辆；3：终端已被注册；4：数据库中无该终端
	TokenCode   string //鉴权码
}

func ParsePlatformRegAnswer(p jtt808.Jtt808) PlatformRegAnswer {
	pa := PlatformRegAnswer{}
	pa.Head = p.Head
	body := p.GetBody()
	pa.AnswerRegSN = binary.BigEndian.Uint16(body[0:2])
	pa.Result = body[2]
	pa.TokenCode = string(body[3:])
	pa.TokenCode = jtt808.ToGBK(pa.TokenCode)
	return pa
}
